*****************************************************************************
*****************************************************************************
**** PULESA OOP PILOT DATA ANALYSIS               						 ****
**** Replication file for Cameron et al. 2024 in PLoS:GPH				 ****
**** "Current Current out of pocket care costs among HIV and 	 		 ****
**** hypertension co-morbid patients in urban and peri-urban Uganda" 	 ****
****																 	 ****				  
**** Lily Morrell and Drew Cameron	        	 						 ****
**** Last Updated														 ****
**** 3 Sept 2024						     							 ****
**** Also edited by Christian Arega		  						         ****
****																	 ****
**** For questions please contact drew.cameron@yale.edu					 ****
*****************************************************************************
*****************************************************************************

// Set Stata preferences 
	clear all
	set more off
	set mem 2g
	
**=========================================================================**
**======================================================================== **
**                                                                         **
**     Setting local paths						                           **
**                                                                         **
**     Enter filepath as appropriate...              					   **
**     Then Read in data and create log file                               **
**                                                                         **
**                                                                         **
**                                                                         **
**	** In the main folder "Cameron_Morrell_2024"                           **
**		** Filepath should contain the following sub folders:              **
**		// /dataset											               **
**				// /Cameron_Morrell_et_al_2024.dta			               **
**		// /do_files								    		           **
**				// /Cameron_Morrell et al. 2024.do         			       **
**		// /tables														   **
**				// appendix 											   **
**											            				   **								
**=========================================================================**
**=========================================================================**

/*
	** Temporary filepath for New User - enter your unique filepath here "..."
	local temp_path1 ".../Cameron_Morrell_2024"	
	local temp_path2 ".../Cameron_Morrell_2024/tables/"
	local temp_path3 ".../Cameron_Morrell_2024/figures/"

	cd "`temp_path1'"
	use `temp_path1'/dataset/Cameron_Morrell_et_al_2024.dta
*/	


**=========================================================================**
**======================================================================== **
**                                                                         **
**    ANALYSIS: Tables 2-6, Figure 1, and Appendix Table 1				   **
** 																		   **
**    From Lily Morrell and Drew Cameron                                   **
**                                                                         **
**=========================================================================**
**=========================================================================**;

cd "`temp_path2'"

**=========================================================================**
**======================================================================== **
**                                                                         **
**     Table 2. Descriptive Statistics					                   **
**                                                                         **
**=========================================================================**
**=========================================================================**;

	** Create Table 2 (XLSX File)

	local table2a age_p female mstatus1 moreschool employed distfacility longtrip_hiv longtrip_htn diffhtnfacility netearn1 spendpeople 

	local table2b arrangecare_hiv arrangecare_htn payfood_hiv payfood_htn losewages_hiv losewages_htn 

	local table2c admitfacility admit_htn

	label var age_p "Age"
	label var female "Female"
	label var mstatus1 "Married"
	label var moreschool "Secondary education or better"
	label var employed "Employed"
	label var distfacility "Distance to HIV facility (km)"
	label var longtrip_hiv "Time to HIV facility (hours)"
	label var longtrip_htn "Time to HTN facility (hours)"
	label var diffhtnfacility "Patients who visit different facility for HTN care"
	label var netearn1 "Monthly HH invome (USD)"
	label var spendpeople "Monthly HH expenditure (USD)"
	label var arrangecare_hiv "Patients who used childcare (HIV visit)"
	label var arrangecare_htn "Patients who used childcare (HTN visit)"
	label var payfood_hiv "Patients who paid for food (HIV visit)"
	label var payfood_htn "Patients who paid for food (HTN visit)"
	label var losewages_hiv "Patients who lost wages or earnings (HIV visit)"
	label var losewages_htn "Patients who lost wages or earnings (HTN visit)"
	label var admitfacility "Patients who had any hospitalizations for HIV"
	label var admit_htn "Patients who had any hospitalization for HTN"

	local row=6
	local fmt %9.2fc
	local fmt1 %9.3fc

	putexcel set "Tables_2_3_4_A1_A2.xlsx", sheet("Table 2") modify
	putexcel A1 = "Table 2. Descriptive statistics (means) for full sample and by lockdown status" A5 = "DEMOGRAPHICS" A28 = "STATISTICS AT LAST CLINIC VISIT" A41 = "WITHIN THE LAST 12 MONTHS" B2 = "Full sample (n=94)" B3 = "Mean" B4 = "[SD]" C4 = "n" D2 = "Full lockdown (n=30)" D3 = "Mean" D4= "(SE)" E4 = "n" F2 = "Partial lockdown (n=64)" F3 = "Mean" F4 = "(SE)" G4 = "n" H4 = "p-value" 

	foreach v in `table2a'{
		qui sum `v', d
		local mu1 = string(r(mean), "`fmt'")
		local sd1 = string(r(sd), "`fmt'")
		local ob = string(r(N), "%9.0f")
		
		qui sum `v' if under_lockdown == 1, d
		local mu2 = string(r(mean), "`fmt'")
		local se2 = string(r(sd)/sqrt(r(N)), "`fmt'")
		local ob2 = string(r(N), "%9.0f")
		
		qui sum `v' if under_lockdown == 0, d
		local mu3 = string(r(mean), "`fmt'")
		local se3 = string(r(sd)/sqrt(r(N)), "`fmt'")
		local ob3 = string(r(N), "%9.0f")
		
		ttest `v', by(under_lockdown)
		local muP = string(r(p),"`fmt1'")
			if r(p) < 0.001 {
				local sig_level "***"
			}
			else if r(p) < 0.05 {
				local sig_level "**"
			}
			else if r(p) < 0.10 {
				local sig_level "*"
			}
			else {
				local sig_level ""
			}
		local label: variable label `v'
	   
		putexcel A`row'="`label'"
		putexcel B`row'="`mu1'"
		putexcel B`=`row'+1' = "[`sd1']"
		putexcel C`row'="`ob'"
		putexcel D`row'="`mu2'"
		putexcel D`=`row'+1'="(`se2')"
		putexcel E`row'="`ob2'"
		putexcel F`row'="`mu3'"
		putexcel F`=`row'+1'="(`se3')"
		putexcel G`row'="`ob3'"
		putexcel H`row' = "`muP'`sig_level'"

		local row = `row'+2
	}

	local row=29

	foreach v in `table2b'{
		qui sum `v', d
		local mu1 = string(r(mean), "`fmt'")
		local sd1 = string(r(sd), "`fmt'")
		local ob = string(r(N), "%9.0f")
		
		qui sum `v' if under_lockdown == 1, d
		local mu2 = string(r(mean), "`fmt'")
		local se2 = string(r(sd)/sqrt(r(N)), "`fmt'")
		local ob2 = string(r(N), "%9.0f")
		
		qui sum `v' if under_lockdown == 0, d
		local mu3 = string(r(mean), "`fmt'")
		local se3 = string(r(sd)/sqrt(r(N)), "`fmt'")
		local ob3 = string(r(N), "%9.0f")
		
		ttest `v', by(under_lockdown)
		local muP = string(r(p),"`fmt1'")
			if r(p) < 0.001 {
				local sig_level "***"
			}
			else if r(p) < 0.05 {
				local sig_level "**"
			}
			else if r(p) < 0.10 {
				local sig_level "*"
			}
			else {
				local sig_level ""
			}
		local label: variable label `v'
	   
		putexcel A`row'="`label'"
		putexcel B`row'="`mu1'"
		putexcel B`=`row'+1' = "[`sd1']"
		putexcel C`row'="`ob'"
		putexcel D`row'="`mu2'"
		putexcel D`=`row'+1'="(`se2')"
		putexcel E`row'="`ob2'"
		putexcel F`row'="`mu3'"
		putexcel F`=`row'+1'="(`se3')"
		putexcel G`row'="`ob3'"
		putexcel H`row' = "`muP'`sig_level'"

		local row = `row'+2
	}

	local row=42

	foreach v in `table2c'{
		qui sum `v', d
		local mu1 = string(r(mean), "`fmt'")
		local sd1 = string(r(sd), "`fmt'")
		local ob = string(r(N), "%9.0f")
		
		qui sum `v' if under_lockdown == 1, d
		local mu2 = string(r(mean), "`fmt'")
		local se2 = string(r(sd)/sqrt(r(N)), "`fmt'")
		local ob2 = string(r(N), "%9.0f")
		
		qui sum `v' if under_lockdown == 0, d
		local mu3 = string(r(mean), "`fmt'")
		local se3 = string(r(sd)/sqrt(r(N)), "`fmt'")
		local ob3 = string(r(N), "%9.0f")
		
		ttest `v', by(under_lockdown)
		local muP = string(r(p),"`fmt1'")
			if r(p) < 0.001 {
				local sig_level "***"
			}
			else if r(p) < 0.05 {
				local sig_level "**"
			}
			else if r(p) < 0.10 {
				local sig_level "*"
			}
			else {
				local sig_level ""
			}
		local label: variable label `v'
	   
		putexcel A`row'="`label'"
		putexcel B`row'="`mu1'"
		putexcel B`=`row'+1' = "[`sd1']"
		putexcel C`row'="`ob'"
		putexcel D`row'="`mu2'"
		putexcel D`=`row'+1'="(`se2')"
		putexcel E`row'="`ob2'"
		putexcel F`row'="`mu3'"
		putexcel F`=`row'+1'="(`se3')"
		putexcel G`row'="`ob3'"
		putexcel H`row' = "`muP'`sig_level'"

		local row = `row'+2
	}
	putexcel A46 = "Notes: Standard deviations reported in brackets; Standard errors reported in parenthesis; Student's t-tests for each row examine mean difference between sample taken during full lockdown vs. partial lockdown; *** p<0.01, ** p<0.05, * p<0.1."
	putexcel close

**=========================================================================**
**======================================================================== **
**                                                                         **
**     Table 3. Cost (USD) Per Visit Breakdown							   **
**                                                                         **
**=========================================================================**
**=========================================================================**;

	** Create Table 3 (XLSX File)

	local table3a direct_hivcost indirect_hivcost_noopp costtrip_hiv paycare_hiv temp_mpayfood_hiv temp_mcostclinic_hiv opportunitycosts_hiv totalcost_hiv_noopp totalcost_hiv

	local table3b direct_htncost_pv pecuinaryindirect_htn_pv costtrip_htn temp_paycare_htn temp_mpayfood_htn temp_mcostclinic_htn opportunitycosts_htn_pv totalcost_htn_no_pv totalcost_htn_pv

	label var direct_hivcost "Total direct cost"
	label var indirect_hivcost_noopp "Total indirect cost"
	label var costtrip_hiv "Transport costs (one-way)"
	label var paycare_hiv "HH care costs"
	label var temp_mpayfood_hiv "Additional food expenses"
	label var temp_mcostclinic_hiv "Other costs"
	label var opportunitycosts_hiv "Total opportunity cost"
	label var totalcost_hiv_noopp "Total (Direct + Indirect)"
	label var totalcost_hiv "Total (Direct + Indirect + Opportunity)"

	label var direct_htncost_pv "Total direct cost"
	label var pecuinaryindirect_htn_pv "Total indirect cost"
	label var costtrip_htn "Transport costs (one-way)"
	label var temp_paycare_htn "HH care costs"
	label var temp_mpayfood_htn "Additional food expenses"
	label var temp_mcostclinic_htn "Other costs"
	label var opportunitycosts_htn_pv "Total opportunity cost"
	label var totalcost_htn_no_pv "Total (Direct + Indirect)"
	label var totalcost_htn_pv "Total (Direct + Indirect + Opportunity)"

	local row=6
	local fmt %9.2fc
	local fmt1 %9.3fc

	putexcel set "Tables_2_3_4_A1_A2.xlsx", sheet("Table 3") modify
	putexcel A1 = "Table 3. Median cost (USD) per visit breakdown" A26 = "Table 3. Median cost (USD) per visit breakdown (cont'd)" A5 = "HIV CARE" A30 = "HTN CARE" B2 = "Full sample" BB3 = "Median" B4 = "[IQR]" C2 = "Full lockdown" C3 = "Median" C4= "[IQR]" D2 = "Partial lockdown" D3 = "Median" D4 = "[IQR]" A24 = "n" A49 = "n" B27 = "Full sample" C27 = "Full lockdown" D27 = "Partial lockdown" B28 = "Median" C28 = "Median" D28 = "Median" B29 = "[IQR]" C29 = "[IQR]" D29 = "[IQR]" B3 = "Median"

	foreach v in `table3a'{
		qui sum `v', d
		local mu1 = string(r(p50), "`fmt'")
		local p25_1 = string(r(p25), "`fmt'")
		local p75_1 = string(r(p75), "`fmt'")	
		local ob1 = string(r(N), "%9.0f")
		
		qui sum `v' if under_lockdown == 1, d
		local mu2 = string(r(p50), "`fmt'")
		local p25_2 = string(r(p25), "`fmt'")
		local p75_2 = string(r(p75), "`fmt'")	
		local ob2 = string(r(N), "%9.0f")
		
		qui sum `v' if under_lockdown == 0, d
		local mu3 = string(r(p50), "`fmt'")
		local p25_3 = string(r(p25), "`fmt'")
		local p75_3 = string(r(p75), "`fmt'")		
		local ob3 = string(r(N), "%9.0f")
		
		local label: variable label `v'
	   
		putexcel A`row'="`label'"
		putexcel B`row'="$`mu1'"
		putexcel B`=`row'+1' = "[$`p25_1' - $`p75_1']"
		putexcel C`row'="$`mu2'"
		putexcel C`=`row'+1'= "[$`p25_2' - $`p75_2']"
		putexcel D`row'="$`mu3'"
		putexcel D`=`row'+1'="[$`p25_3' - $`p75_3']"

		local row = `row'+2
	}

	local row = 24
	foreach v in `table3a'{
		qui sum `v', d
		local ob1 = string(r(N), "%9.0f")
		
		qui sum `v' if under_lockdown == 1, d
		local ob2 = string(r(N), "%9.0f")
		
		qui sum `v' if under_lockdown == 0, d
		local ob3 = string(r(N), "%9.0f")
		
		local label: variable label `v'
	   
		putexcel B`row'="`ob1'"
		putexcel C`row'="`ob2'"
		putexcel D`row'="`ob3'"
	}

	local row=31
	foreach v in `table3b'{
		qui sum `v', d
		local mu1 = string(r(p50), "`fmt'")
		local p25_1 = string(r(p25), "`fmt'")
		local p75_1 = string(r(p75), "`fmt'")	
		local ob1 = string(r(N), "%9.0f")

		qui sum `v' if under_lockdown == 1, d
		local mu2 = string(r(p50), "`fmt'")
		local p25_2 = string(r(p25), "`fmt'")
		local p75_2 = string(r(p75), "`fmt'")	
		local ob2 = string(r(N), "%9.0f")

		qui sum `v' if under_lockdown == 0, d
		local mu3 = string(r(p50), "`fmt'")
		local p25_3 = string(r(p25), "`fmt'")
		local p75_3 = string(r(p75), "`fmt'")	
		local ob3 = string(r(N), "%9.0f")

		local label: variable label `v'
	   
		putexcel A`row'="`label'"
		putexcel B`row'="$`mu1'"
		putexcel B`=`row'+1' = "[$`p25_1' - $`p75_1']"
		putexcel C`row'="$`mu2'"
		putexcel C`=`row'+1'= "[$`p25_2' - $`p75_2']"
		putexcel D`row'="$`mu3'"
		putexcel D`=`row'+1'="[$`p25_3' - $`p75_3']"

		local row = `row'+2
	}

	local row = 49
	foreach v in `table3b'{
		qui sum `v', d
		local ob1 = string(r(N), "%9.0f")
		
		qui sum `v' if under_lockdown == 1, d
		local ob2 = string(r(N), "%9.0f")
		
		qui sum `v' if under_lockdown == 0, d
		local ob3 = string(r(N), "%9.0f")
		
		local label: variable label `v'
	   
		putexcel B`row'="`ob1'"
		putexcel C`row'="`ob2'"
		putexcel D`row'="`ob3'"
	}

	putexcel A50 = "Notes: Though not individually reported, total direct costs of care for HIV and HTN included costs related to facility user fees, consultation fees, laboratory and test fees, and drug costs; Interquartile ranges (IQR: 25th – 75th percentiles) are reported in brackets; Direct costs include facility user fees, consultation fees, laboratory and test fees, and drug costs; Other costs include cellular service fees, fines from law enforcement, and informal payments; Indirect cost totals and all financial and economic totals account for round-trip transportation costs. No missing values were observed for any of the reported cost inputs."
	putexcel close


************************************************
************************************************
** In Text citation following Table 3
** For reference on manuscript page 19-20 lines 314-322
************************************************
************************************************
	
	** "(Financial) "median per-visit cost for HTN care among those who report using the same HIV facility"
	sum totalcost_htn_no_pv if diffhtnfacility==0,d
		
	** "those using different facilities report a per-visit (financial) cost of"
	sum totalcost_htn_no_pv if diffhtnfacility==1,d
		
	** "median per-visit (economic) cost for HTN care among those who report using the same HIV facility"
	sum totalcost_htn_pv if diffhtnfacility==0,d	
	
	** "those using different facilities report a per-visit (economic) cost of" 
	sum totalcost_htn_pv if diffhtnfacility==1,d

		** Using student's t-test, we find that mean differences are flipped
		ttest totalcost_htn_no_pv, by(diffhtnfacility)
		ttest totalcost_htn_pv, by(diffhtnfacility)
		
**=========================================================================**
**======================================================================== **
**                                                                         **
**     Appendix Table A1. Cost (USD) Per Visit Breakdown				   **
**                                                                         **
**=========================================================================**
**=========================================================================**;

	** Create Appendix Table A1 (XLSX File)

local table3Aa direct_hivcost indirect_hivcost_noopp costtrip_hiv paycare_hiv temp_mpayfood_hiv temp_mcostclinic_hiv opportunitycosts_hiv totalcost_hiv_noopp totalcost_hiv

local table3Ab direct_htncost_pv pecuinaryindirect_htn_pv costtrip_htn temp_paycare_htn temp_mpayfood_htn temp_mcostclinic_htn opportunitycosts_htn_pv totalcost_htn_no_pv totalcost_htn_pv

local row=6
local fmt %9.2fc
local fmt1 %9.3fc

putexcel set "Tables_2_3_4_A1_A2.xlsx", sheet("Appendix Table A1") modify
putexcel A1 = "Appendix Table A1. Mean cost (USD) per visit breakdown" A26 = "Appendix Table A1. Mean cost (USD) per visit breakdown (cont'd)" A5 = "HIV CARE" A30 = "HTN CARE" B2 = "Full sample" C4 = "n" D2 = "Full lockdown" D3 = "Mean" E4 = "n" D4= "(SE)" F2 = "Partial lockdown" F3 = "Mean" F4 = "(SE)" G4 = "n" H4 = "p-value" B27 = "Full sample" B28 = "Mean" B29 = "[SD]" C29 = "n" C27 = "Full lockdown" C29 = "(SE)" D29 = "n" E27 = "Partial lockdown" E28 = "Mean" E29 = "(SE)" F29 = "n" G29 = "p-value" B3 = "Mean" B4 = "[SD]"

foreach v in `table3Aa'{
	qui sum `v', d
    local mu1 = string(r(mean), "`fmt'")
	local sd1 = string(r(sd), "`fmt'")
	local ob = string(r(N), "%9.0f")
	
	qui sum `v' if under_lockdown == 1, d
    local mu2 = string(r(mean), "`fmt'")
	local se2 = string(r(sd)/sqrt(r(N)), "`fmt'")
	local ob2 = string(r(N), "%9.0f")
	
	qui sum `v' if under_lockdown == 0, d
    local mu3 = string(r(mean), "`fmt'")
	local se3 = string(r(sd)/sqrt(r(N)), "`fmt'")
	local ob3 = string(r(N), "%9.0f")
	
	ttest `v', by(under_lockdown)
    local muP = string(r(p),"`fmt1'")
        if r(p) < 0.001 {
            local sig_level "***"
        }
        else if r(p) < 0.05 {
            local sig_level "**"
        }
        else if r(p) < 0.10 {
            local sig_level "*"
        }
        else {
            local sig_level ""
        }
	local label: variable label `v'
   
    putexcel A`row'="`label'"
	putexcel B`row'="$`mu1'"
	putexcel B`=`row'+1' = "[$`sd1']"
	putexcel C`row'="`ob'"
	putexcel D`row'="$`mu2'"
	putexcel D`=`row'+1'="($`se2')"
	putexcel E`row'="`ob2'"
	putexcel F`row'="$`mu3'"
	putexcel F`=`row'+1'="($`se3')"
	putexcel G`row'="`ob3'"
	putexcel H`row' = "`muP'`sig_level'"

	local row = `row'+2
}

local row=31
foreach v in `table3Ab'{
		qui sum `v', d
    local mu1 = string(r(mean), "`fmt'")
	local sd1 = string(r(sd), "`fmt'")
	local ob = string(r(N), "%9.0f")
	
	qui sum `v' if under_lockdown == 1, d
    local mu2 = string(r(mean), "`fmt'")
	local se2 = string(r(sd)/sqrt(r(N)), "`fmt'")
	local ob2 = string(r(N), "%9.0f")
	
	qui sum `v' if under_lockdown == 0, d
    local mu3 = string(r(mean), "`fmt'")
	local se3 = string(r(sd)/sqrt(r(N)), "`fmt'")
	local ob3 = string(r(N), "%9.0f")
	
	ttest `v', by(under_lockdown)
    local muP = string(r(p),"`fmt1'")
        if r(p) < 0.001 {
            local sig_level "***"
        }
        else if r(p) < 0.05 {
            local sig_level "**"
        }
        else if r(p) < 0.10 {
            local sig_level "*"
        }
        else {
            local sig_level ""
        }
	local label: variable label `v'
   
    putexcel A`row'="`label'"
	putexcel B`row'="$`mu1'"
	putexcel B`=`row'+1' = "[$`sd1']"
	putexcel C`row'="`ob'"
	putexcel D`row'="$`mu2'"
	putexcel D`=`row'+1'="($`se2')"
	putexcel E`row'="`ob2'"
	putexcel F`row'="$`mu3'"
	putexcel F`=`row'+1'="($`se3')"
	putexcel G`row'="`ob3'"
	putexcel H`row' = "`muP'`sig_level'"

	local row = `row'+2
}

putexcel A49 = "Notes: Though not individually reported, total direct costs of care for HIV and HTN included costs related to facility user fees, consultation fees, laboratory and test fees, and drug costs; Standard Deviations are in brackets; Standard Errors are in parenthesis; *** p<0.01, ** p<0.05, * p<0.1; Direct costs include facility user fees, consultation fees, laboratory and test fees, and drug costs; Other costs include cellular service fees, fines from law enforcement, and informal payments; Indirect cost totals and all financial and economic totals account for round-trip transportation costs."
putexcel close


**=========================================================================**
**======================================================================== **
**                                                                         **
**     Figure 1. Percent of Spending							           **
**                                                                         **
**=========================================================================**
**=========================================================================**;
cd "`temp_path3'"

	** Create Data for Figure 1 (XLSX File)

	local figure1a direct_htncost_pv pecuinaryindirect_htn_pv opportunitycosts_htn_pv direct_htncost_pv pecuinaryindirect_htn_pv figureoppcosthtn direct_hivcost indirect_hivcost_noopp opportunitycosts_hiv direct_hivcost indirect_hivcost_noop  figureoppcosthiv

	label var direct_htncost_pv "Direct cost" 
	label var pecuinaryindirect_htn_pv "Indirect cost"
	label var opportunitycosts_htn_pv "Opportunity cost"
	label var figureoppcosthtn "Opportunity cost"
	label var direct_hivcost "Direct cost"
	label var indirect_hivcost_noopp "Indirect cost"
	label var opportunitycosts_hiv "Opportunity cost"
	label var figureoppcosthiv "Opportunity cost"

	local row=2
	local fmt %9.2fc
	local fmt1 %9.3fc

	putexcel set "Figure1.xlsx", sheet("data_PULESA") modify
	putexcel A1 = "Color" B1 = "Cat" C1 = "USD" D1 = "Order"
	putexcel B2 = "HTN (economic costs)" B3 = "HTN (economic costs)"  B4 = "HTN (economic costs)" B5 = "HTN (financial costs)" B6 = "HTN (financial costs)" B7 = "HTN (financial costs)" B8 = "HIV (economic costs)" B9 = "HIV (economic costs)" B10 = "HIV (economic costs)" B11 = "HIV (financial costs)" B12 = "HIV (financial costs)" B13 = "HIV (financial costs)"
	putexcel D2 = "1" D3 = "1" D4 = "1" D5 = "2" D6 = "2" D7 = "2" D8 = "3" D9 = "3" D10 = "3" D11 = "4" D12 = "4" D13 = "4"

	foreach v in `figure1a'{
		qui sum `v', d
		local mu1 = string(r(mean), "`fmt'")
		
		local label: variable label `v'
	 
	 putexcel A`row'="`label'"	
		putexcel C`row'="`mu1'"
		local row = `row'+1
		
	}  

	local figure1bi direct_htncost_pv pecuinaryindirect_htn_pv opportunitycosts_htn_pv 
	local figure1bii direct_htncost_pv pecuinaryindirect_htn_pv figureoppcosthtn
	local figure1biii direct_hivcost indirect_hivcost_noopp opportunitycosts_hiv
	local figure1biv direct_hivcost indirect_hivcost_noop  figureoppcosthiv
	qui sum totalcost_htn_pv, d
		local total1 = string(r(mean))
	qui sum totalcost_htn_no_pv, d
		local total2 = string(r(mean))
	qui sum totalcost_hiv
		local total3 = string(r(mean))
	qui sum totalcost_hiv_noopp
		local total4 = string(r(mean))

	local row=2
	local fmt %9.2fc
	local fmt1 %9.3fc

	putexcel set "Figure1.xlsx", sheet("data_PULESA_2") modify
	putexcel A1 = "Color" B1 = "Cat" C1 = "PERCENTAGE" D1 = "Order"
	putexcel B2 = "HTN (economic costs)" B3 = "HTN (economic costs)"  B4 = "HTN (economic costs)" B5 = "HTN (financial costs)" B6 = "HTN (financial costs)" B7 = "HTN (financial costs)" B8 = "HIV (economic costs)" B9 = "HIV (economic costs)" B10 = "HIV (economic costs)" B11 = "HIV (financial costs)" B12 = "HIV (financial costs)" B13 = "HIV (financial costs)"
	putexcel D2 = "1" D3 = "1" D4 = "1" D5 = "2" D6 = "2" D7 = "2" D8 = "3" D9 = "3" D10 = "3" D11 = "4" D12 = "4" D13 = "4"

	foreach v in `figure1bi' {
		qui sum `v', d
		local mu1 = string(((r(mean)/`total1')*100), "`fmt'")
		
		local label: variable label `v'
	 
	 putexcel A`row'="`label'"	
		putexcel C`row'="`mu1'"
		local row = `row'+1
		
	}

	local row=5

	foreach v in `figure1bii' {
		qui sum `v', d
		local mu2 = string(((r(mean)/`total2')*100), "`fmt'")
		
		local label: variable label `v'
	 
	 putexcel A`row'="`label'"	
		putexcel C`row'="`mu2'"
		local row = `row'+1
		
	}

	local row=8

	foreach v in `figure1biii' {
		qui sum `v', d
		local mu3 = string(((r(mean)/`total3')*100), "`fmt'")
		
		local label: variable label `v'
	 
	 putexcel A`row'="`label'"	
		putexcel C`row'="`mu3'"
		local row = `row'+1
		
	}

	local row=11

	foreach v in `figure1biv' {
		qui sum `v', d
		local mu4 = string(((r(mean)/`total4')*100), "`fmt'")
		
		local label: variable label `v'
	 
	 putexcel A`row'="`label'"	
		putexcel C`row'="`mu4'"
		local row = `row'+1
		
	}
	putexcel close

	** Create Data for Figure 1 (CSV File)
	
	local figure1a direct_htncost_pv pecuinaryindirect_htn_pv opportunitycosts_htn_pv direct_htncost_pv pecuinaryindirect_htn_pv figureoppcosthtn direct_hivcost indirect_hivcost_noopp opportunitycosts_hiv direct_hivcost indirect_hivcost_noop  figureoppcosthiv

	label var direct_htncost_pv "Direct cost" 
	label var pecuinaryindirect_htn_pv "Indirect cost"
	label var opportunitycosts_htn_pv "Opportunity cost"
	label var figureoppcosthtn "Opportunity cost"
	label var direct_hivcost "Direct cost"
	label var indirect_hivcost_noopp "Indirect cost"
	label var opportunitycosts_hiv "Opportunity cost"
	label var figureoppcosthiv "Opportunity cost"

	local row=2
	local fmt %9.2fc
	local fmt1 %9.3fc

	putexcel set "data_PULESA.csv", modify
	putexcel A1 = "Color" B1 = "Cat" C1 = "USD" D1 = "Order"
	putexcel B2 = "HTN (economic costs)" B3 = "HTN (economic costs)"  B4 = "HTN (economic costs)" B5 = "HTN (financial costs)" B6 = "HTN (financial costs)" B7 = "HTN (financial costs)" B8 = "HIV (economic costs)" B9 = "HIV (economic costs)" B10 = "HIV (economic costs)" B11 = "HIV (financial costs)" B12 = "HIV (financial costs)" B13 = "HIV (financial costs)"
	putexcel D2 = "1" D3 = "1" D4 = "1" D5 = "2" D6 = "2" D7 = "2" D8 = "3" D9 = "3" D10 = "3" D11 = "4" D12 = "4" D13 = "4"

	foreach v in `figure1a'{
		qui sum `v', d
		local mu1 = string(r(mean), "`fmt'")
		
		local label: variable label `v'
	 
	 putexcel A`row'="`label'"	
		putexcel C`row'="`mu1'"
		local row = `row'+1
		
	}  

	local figure1bi direct_htncost_pv pecuinaryindirect_htn_pv opportunitycosts_htn_pv 
	local figure1bii direct_htncost_pv pecuinaryindirect_htn_pv figureoppcosthtn
	local figure1biii direct_hivcost indirect_hivcost_noopp opportunitycosts_hiv
	local figure1biv direct_hivcost indirect_hivcost_noop  figureoppcosthiv
	qui sum totalcost_htn_pv, d
		local total1 = string(r(mean))
	qui sum totalcost_htn_no_pv, d
		local total2 = string(r(mean))
	qui sum totalcost_hiv
		local total3 = string(r(mean))
	qui sum totalcost_hiv_noopp
		local total4 = string(r(mean))

	local row=2
	local fmt %9.2fc
	local fmt1 %9.3fc

	putexcel set "data_PULESA2.csv", modify
	putexcel A1 = "Color" B1 = "Cat" C1 = "PERCENTAGE" D1 = "Order"
	putexcel B2 = "HTN (economic costs)" B3 = "HTN (economic costs)"  B4 = "HTN (economic costs)" B5 = "HTN (financial costs)" B6 = "HTN (financial costs)" B7 = "HTN (financial costs)" B8 = "HIV (economic costs)" B9 = "HIV (economic costs)" B10 = "HIV (economic costs)" B11 = "HIV (financial costs)" B12 = "HIV (financial costs)" B13 = "HIV (financial costs)"
	putexcel D2 = "1" D3 = "1" D4 = "1" D5 = "2" D6 = "2" D7 = "2" D8 = "3" D9 = "3" D10 = "3" D11 = "4" D12 = "4" D13 = "4"

	foreach v in `figure1bi' {
		qui sum `v', d
		local mu1 = string(((r(mean)/`total1')*100), "`fmt'")
		
		local label: variable label `v'
	 
	 putexcel A`row'="`label'"	
		putexcel C`row'="`mu1'"
		local row = `row'+1
		
	}

	local row=5

	foreach v in `figure1bii' {
		qui sum `v', d
		local mu2 = string(((r(mean)/`total2')*100), "`fmt'")
		
		local label: variable label `v'
	 
	 putexcel A`row'="`label'"	
		putexcel C`row'="`mu2'"
		local row = `row'+1
		
	}

	local row=8

	foreach v in `figure1biii' {
		qui sum `v', d
		local mu3 = string(((r(mean)/`total3')*100), "`fmt'")
		
		local label: variable label `v'
	 
	 putexcel A`row'="`label'"	
		putexcel C`row'="`mu3'"
		local row = `row'+1
		
	}

	local row=11

	foreach v in `figure1biv' {
		qui sum `v', d
		local mu4 = string(((r(mean)/`total4')*100), "`fmt'")
		
		local label: variable label `v'
	 
	 putexcel A`row'="`label'"	
		putexcel C`row'="`mu4'"
		local row = `row'+1
		
	}
	putexcel close
**=========================================================================**
**======================================================================== **
**                                                                         **
**     Table 4 and Appendix Table 1. (Mean and Median Monthly Care Costs)  **
**                                                                         **
**=========================================================================**
**=========================================================================**;
cd "`temp_path2'"

	** Create Table A4 (XLSX File)

	local table4a monthly_timesclinic_hiv monthly_costs_hiv_no monthly_costs_hiv totalcosts_hiv_incperc_no totalcosts_hiv_incperc totalcosts_hiv_expperc_no  totalcosts_hiv_expperc

	local table4b monthly_timesclinic_htn monthly_meds m_totalcost_htn_no m_totalcost_htn totalcost_htn_inperc_no totalcosts_htn_incperc totalcost_htn_expperc_no totalcost_htn_expperc 

	local table4c admit_htn admittimes_htn hospitalcosts

	label var monthly_timesclinic_hiv "Projected number of monthly visits"
	label var monthly_costs_hiv_no "Monthly total HIV care costs (USD) [Financial Costs]"
	label var monthly_costs_hiv "Monthly total HIV care costs (USD) [Economic Costs]"
	label var totalcosts_hiv_incperc_no "Monthly HIV costs as % of HH income [Financial Costs]"
	label var totalcosts_hiv_incperc "Monthly HIV costs as % of HH income [Economic Costs]"
	label var totalcosts_hiv_expperc_no "Monthly HIV costs as % of HH expenditure [Financial Costs]"
	label var totalcosts_hiv_expperc "Monthly HIV costs as % of HH expenditure [Economic Costs]"

	label var monthly_timesclinic_htn "Projected number of monthly visits"
	label var monthly_meds "Drug costs (USD)"
	label var m_totalcost_htn_no "Monthly total HTN care costs (USD) [Financial Costs]"
	label var m_totalcost_htn "Monthly total HTN care costs (USD) [Economic Costs]"
	label var totalcost_htn_inperc_no "HTN costs as % of HH income [Financial Costs]"
	label var totalcosts_htn_incperc "HTN costs as % of HH income [Economic Costs]"
	label var totalcost_htn_expperc_no "HTN costs as % of HH expenditure [Financial Costs]"
	label var totalcost_htn_expperc "HTN costs as % of HH expenditure [Economic Costs]"

	label var admit_htn "% hospitalized for HTN in last 12 months"
	label var admittimes_htn "Number of hospital stays in last 12 months"
	label var hospitalcosts "Per hospitalization stay cost (USD)"

	local row=5
	local fmt %9.2fc
	local fmt1 %9.3fc

	putexcel set "Tables_2_3_4_A1_A2.xlsx", sheet("Table 4") modify
	putexcel A1 = "Table 4. Median monthly care costs, projected visits, and hospitalization costs" A4 = "Monthly HIV care" B2 = "Median" B3 = "[IQR]" C3 = "n" A19 = "Monthly HTN care" A36 = "Hospitalization (HTN)"

	foreach v in `table4a'{
		qui sum `v', d
		local mu1 = string(r(p50), "`fmt'")
		local p25_1 = string(r(p25), "`fmt'")
		local p75_1 = string(r(p75), "`fmt'")	
		local ob1 = string(r(N), "%9.0f")
		
		local label: variable label `v'
	   
		putexcel A`row'="`label'"
		putexcel B`row'="`mu1'"
		putexcel B`=`row'+1' = "[`p25_1' - `p75_1']"
		putexcel C`row' = "`ob1'"

		local row = `row'+2
	}

	local row = 20
	foreach v in `table4b'{
		qui sum `v', d
		local mu1 = string(r(p50), "`fmt'")
		local p25_1 = string(r(p25), "`fmt'")
		local p75_1 = string(r(p75), "`fmt'")	
		local ob1 = string(r(N), "%9.0f")
		
		local label: variable label `v'
	   
		putexcel A`row'="`label'"
		putexcel B`row'="`mu1'"
		putexcel B`=`row'+1' = "[`p25_1' - `p75_1']"
		putexcel C`row' = "`ob1'"

		local row = `row'+2
	}

	local row=37
	foreach v in `table4c'{
			qui sum `v', d
		local mu1 = string(r(p50), "`fmt'")
		local p25_1 = string(r(p25), "`fmt'")
		local p75_1 = string(r(p75), "`fmt'")	
		local ob1 = string(r(N), "%9.0f")
		
		local label: variable label `v'
	  
		putexcel A`row'="`label'"
		putexcel B`row'="`mu1'"
		putexcel B`=`row'+1' = "[`p25_1' - `p75_1']"
		putexcel C`row' = "`ob1'"

		local row = `row'+2
	}

	putexcel A43 = "Notes: 'Economic costs' category includes foregone wage earnings due to HIV or HTN visit. 'Financial cost' totals do not include foregone wage earnings from medical visits; Interquartile ranges (IQR: 25th – 75th percentiles) are reported in brackets;; Monthly HTN care costs include hospitalization and drug costs, monthly HIV care costs do not."
	putexcel close

	** Create Appendix Table A2 (XLSX File)

	local table4Aa monthly_timesclinic_hiv monthly_costs_hiv_no monthly_costs_hiv totalcosts_hiv_incperc_no totalcosts_hiv_incperc totalcosts_hiv_expperc_no  totalcosts_hiv_expperc

	local table4Ab monthly_timesclinic_htn monthly_meds m_totalcost_htn_no m_totalcost_htn totalcost_htn_inperc_no totalcosts_htn_incperc totalcost_htn_expperc_no totalcost_htn_expperc 

	local table4Ac admit_htn admittimes_htn hospitalcosts

	local row=5
	local fmt %9.2fc
	local fmt1 %9.3fc

	putexcel set "Tables_2_3_4_A1_A2.xlsx", sheet("Appendix Table A2") modify
	putexcel A1 = "Appendix Table A2. Mean monthly care costs, projected visits, and hospitalization costs" A4 = "Monthly HIV care" B2 = "Mean" B3 = "[SD]" C3 = "n" A19 = "Monthly HTN care" A36 = "Hospitalization (HTN)"

	foreach v in `table4Aa'{
		qui sum `v', d
		local mu1 = string(r(mean), "`fmt'")
		local sd1 = string(r(sd), "`fmt'")
		local ob1 = string(r(N), "%9.0f")
		
		local label: variable label `v'
	   
		putexcel A`row'="`label'"
		putexcel B`row'="`mu1'"
		putexcel B`=`row'+1' = "[`sd1']"
		putexcel C`row' = "`ob1'"

		local row = `row'+2
	}

	local row = 20
	foreach v in `table4Ab'{
		qui sum `v', d
		local mu1 = string(r(mean), "`fmt'")
		local sd1 = string(r(sd), "`fmt'")
		local ob1 = string(r(N), "%9.0f")
		
		local label: variable label `v'
	   
		putexcel A`row'="`label'"
		putexcel B`row'="`mu1'"
		putexcel B`=`row'+1' = "[`sd1']"
		putexcel C`row' = "`ob1'"

		local row = `row'+2
	}

	local row=37
	foreach v in `table4Ac'{
		qui sum `v', d
		local mu1 = string(r(mean), "`fmt'")
		local sd1 = string(r(sd), "`fmt'")
		local ob1 = string(r(N), "%9.0f")
		
		local label: variable label `v'
	   
		putexcel A`row'="`label'"
		putexcel B`row'="`mu1'"
		putexcel B`=`row'+1' = "[`sd1']"
		putexcel C`row' = "`ob1'"

		local row = `row'+2
	}

	putexcel A43 = "Notes: 'Economic costs' category includes foregone wage earnings due to HIV or HTN visit. 'Financial cost' totals do not include foregone wage earnings from medical visits; Standard deviations reported in brackets; Monthly HTN care costs include hospitalization and drug costs, monthly HIV care costs do not."
	putexcel close

*********************************************************
*********************************************************
*********************************************************
** Reported finding in-text on page 20-21, line 343 - 345
*********************************************************
*********************************************************
/*
"Though not reported in the table, 28.7% of respondents (n=27) report borrowing 
money or selling assets to cover the cost of HTN care in the last 12 months, 
at a median value of $58.46 USD (IQR: $29.23 – $210.44)."
*/
tab borrowhtncare
sum borrowtotal,d

*********************************************************
*********************************************************
*********************************************************


**=========================================================================**
**=========================================================================**
**                                                                         **
**      Cost Functions: Tables 5-6                                         **
**                                                                         **
**      From Drew Cameron                                                  **
**                                                                         **
**=========================================================================**
**=========================================================================**;

* Create household expenditure covariates
	sum spendpeople,d
	gen spendpeople_alt=spendpeople
		replace spendpeople_alt=100.105 if spendpeople_alt==.
	gen expenditure_mill=(spendpeople_alt)/100
	gen expenditure_mill2=expenditure_mill*expenditure_mill	

	
	
* Clean variable labels
	label var monthly_costs_hiv_no "Monthly HIV Costs (Dir+Ind)"
	label var monthly_costs_hiv "Monthly HIV Costs (Dir+Ind+Opp)"
	label var m_totalcost_htn_no "Monthly HTN Costs (Dir+Ind)"
	label var m_totalcost_htn "Monthly HTN Costs (Dir+Ind+Opp)"
	label var under_lockdown "Survey conducted under lockdown"
	label var age_p "Age (years)"
	label var age2 "Age^2"
	label var male "Male"
	label var expenditure_mill "HH Expenditure (per 100 USD)"
	label var expenditure_mill2 "HH Expenditure (per 100 USD)^2"
	label var mstatus1 "Respondent is married"
	label var admitfacility "Respondent admitted overnight for HIV care (12 mo)"
	label var admit_htn "Respondent admitted overnight for HTN care (12 mo)"
	label var traveltime_hiv "Travel time to/from HIV facility (hours)"
	label var traveltime_hiv2 "Travel time to/from HIV facility (hours)^2"
	label var traveltime_htn "Travel time to/from HTN facility (hours)"
	label var traveltime_htn2 "Travel time to/from HTN facility (hours)^2"
	label var arrangecare_hiv "Arranged care (child/adult) to attend HIV visit"
	label var arrangecare_htn "Arranged care (child/adult) to attend HTN visit"
	label var monthly_timesclinic_hiv "Number of monthly HIV clinic visits"
	label var monthly_timesclinic_htn "Number of monthly HTN clinic visits"
	label var losewages_hiv "Respondent gave up wages to attend HIV visit"
	label var losewages_htn "Respondent gave up wages to attend HTN visit"
	
* Log travel time HIV // Yes include
	gen log_traveltime_hiv=ln(traveltime_hiv)
	gen log_traveltime_hiv2=log_traveltime_hiv*log_traveltime_hiv
		label var log_traveltime_hiv "Travel time to HIV visit (ln)"
		label var log_traveltime_hiv2 "Travel time to HIV visit (ln)^2"
* Log travel time HTN	
	gen log_traveltime_htn=ln(traveltime_htn)
	gen log_traveltime_htn2=log_traveltime_htn*log_traveltime_htn
		label var log_traveltime_htn "Travel time to HTN visit (ln)"
		label var log_traveltime_htn2 "Travle time to HTN visit (ln)^2"
*Log HIV visits // Yes include
	gen log_monthly_timesclinic_hiv=ln(monthly_timesclinic_hiv)
	gen log_monthly_timesclinic_hiv2=log_monthly_timesclinic_hiv*log_monthly_timesclinic_hiv
		label var log_monthly_timesclinic_hiv "Number of monthly HIV visits (ln)"
		label var log_monthly_timesclinic_hiv2 "Number of monthly HIV visits (ln)^2"
			
*Log HTN visits // Yes
	gen log_monthly_timesclinic_htn=ln(monthly_timesclinic_htn)
	gen log_monthly_timesclinic_htn2=log_monthly_timesclinic_htn*log_monthly_timesclinic_htn
		label var log_monthly_timesclinic_htn "Number of monthly HTN visits (ln)"
		label var log_monthly_timesclinic_htn2 "Number of monthly HTN visits (ln)^2"
	gen monthly_timesclinic_htn2=monthly_timesclinic_htn*monthly_timesclinic_htn
	
	** Facility Size Variable
	gen facility_size=0
		replace facility_size=1310 if facility_no==11
		replace facility_size=11972 if facility_no==12
		replace facility_size=8814 if facility_no==13
		replace facility_size=4732 if facility_no==14
		replace facility_size=7911 if facility_no==15
		replace facility_size=1865 if facility_no==21
		replace facility_size=830 if facility_no==22
		replace facility_size=2221 if facility_no==23
		replace facility_size=852 if facility_no==24
		replace facility_size=1120 if facility_no==25
	
	tab facility_size
	gen log_facsize=ln(facility_size)
	

************************************************
************************************************	
** TABLE 5. HIV COST FUNCTIONS **
************************************************
************************************************

	global updated_transport matatu_only car_only motorcycle_only boda_only multi_modal // walking/biking omitted

* Without Opportuinty Costs
	* MODEL 1 (BASIC)
	glm monthly_costs_hiv_no i.under_lockdown log_monthly_timesclinic_hiv admitfacility arrangecare_hiv traveltime_hiv $updated_transport i.facility_no, link(log) vce(robust)
			*testparm i.facility_no
			*margins, dydx(*)
			est store Model1_1
			putexcel set GLM_AICBIC_Table_5.xlsx, sheet(Model1_HIV) modify
			putexcel A1=`e(aic)' A2=`e(bic)'
	
	* Model 1 (with demo covariates)
	glm monthly_costs_hiv_no i.under_lockdown log_monthly_timesclinic_hiv admitfacility arrangecare_hiv traveltime_hiv $updated_transport age_p male secondary_ed employed expenditure_mill mstatus1 i.facility_no, link(log) vce(robust)
	*testparm i.facility_no
			est store Model1_2
			putexcel set GLM_AICBIC_Table_5.xlsx, sheet(Model2_HIV) modify
			putexcel A1=`e(aic)' A2=`e(bic)'
	lrtest Model1_1 Model1_2, stats force
	
* With Opportuinty Costs	
	* MODEL 2 (BASIC)
	glm monthly_costs_hiv i.under_lockdown log_monthly_timesclinic_hiv admitfacility arrangecare_hiv traveltime_hiv $updated_transport losewages_hiv i.facility_no, link(log) vce(robust)
	*testparm i.facility_no
			est store Model1_3
			putexcel set GLM_AICBIC_Table_5.xlsx, sheet(Model3_HIV) modify
			putexcel A1=`e(aic)' A2=`e(bic)'
	
	* MODEL 2 (with Demo covars)
	glm monthly_costs_hiv i.under_lockdown log_monthly_timesclinic_hiv admitfacility arrangecare_hiv traveltime_hiv $updated_transport i.losewages_hiv age_p male secondary_ed employed expenditure_mill mstatus1 i.facility_no, link(log) vce(robust)
	*testparm i.facility_no
			margins losewages_hiv
			est store Model1_4
			putexcel set GLM_AICBIC_Table_5.xlsx, sheet(Model4_HIV) modify
			putexcel A1=`e(aic)' A2=`e(bic)'
	lrtest Model1_3 Model1_4, stats force
	
	** Output tables to excel 
	outreg2 [Model1_*] using "glm_hiv.xls", side stats(coef se) label dec(2) excel addnote(Note: TBD) title("Table 5. GLM Model for Predictors of Monthly HIV Costs") replace		

	
************************************************	
************************************************	
** TABLE 6. HYPERTENSION COST FUNCTIONS **
************************************************
************************************************

* Without Opportunity Costs
	*Model 3 (basic)
	glm m_totalcost_htn_no i.under_lockdown log_monthly_timesclinic_htn i.admit_htn arrangecare_htn traveltime_htn diffhtnfacility i.facility_no, link(log) vce(robust)
			*testparm i.facility_no
			est store Model2_1
			putexcel set GLM_AICBIC_Table_6.xlsx, sheet(Model1_HTN) modify
			putexcel A1=`e(aic)' A2=`e(bic)'

	*Model 3 (with covariates)
	glm m_totalcost_htn_no i.under_lockdown log_monthly_timesclinic_htn i.admit_htn arrangecare_htn traveltime_htn diffhtnfacility age_p i.male secondary_ed employed expenditure_mill i.mstatus1 i.facility_no, link(log) vce(robust)
			*testparm i.facility_no
			est store Model2_2
			putexcel set GLM_AICBIC_Table_6.xlsx, sheet(Model2_HTN) modify
			putexcel A1=`e(aic)' A2=`e(bic)'
	lrtest Model2_1 Model2_2, stats force 
			
** With opportunity costs **

	*Model 4 (basic)
	glm m_totalcost_htn i.under_lockdown log_monthly_timesclinic_htn i.admit_htn arrangecare_htn traveltime_htn diffhtnfacility i.losewages_htn i.facility_no, link(log) vce(robust)	
			*testparm i.facility_no
			est store Model2_3
			putexcel set GLM_AICBIC_Table_6.xlsx, sheet(Model3_HTN) modify
			putexcel A1=`e(aic)' A2=`e(bic)'
			
	*Model 4 (with demographic covars)
	glm m_totalcost_htn i.under_lockdown log_monthly_timesclinic_htn i.admit_htn arrangecare_htn traveltime_htn diffhtnfacility i.losewages_htn age_p i.male secondary_ed employed expenditure_mill i.mstatus1 i.facility_no, link(log) vce(robust)
			testparm i.facility_no
				*margins under_lockdown
				*margins, at(log_monthly_timesclinic_htn=(.33 .5 1))
				*margins losewages_htn
				*margins male
				*margins mstatus1
			est store Model2_4
			putexcel set GLM_AICBIC_Table_6.xlsx, sheet(Model4_HTN) modify
			putexcel A1=`e(aic)' A2=`e(bic)'
	lrtest Model2_3 Model2_4, stats force
	outreg2 [Model2_*] using "glm_htn.xls", side stats(coef se) label dec(2) excel addnote(Note: TBD) title("Table 6. GLM Model for Predictors of Monthly HTN Costs") replace	
	
	
**********************************************************************************
**********************************************************************************
** .do file appendix of robustness checks
**********************************************************************************
**********************************************************************************
	
	
	* ROBUSTNESS CHECK: Each as a GLMM model (random effects at the cluster level)
	* Mentioned in Findings Section (end) page 27, lines 392-4.
	******************************************************************************
	******************************************************************************
	
	** TABLE 5
	**********
	*M1: 
	meglm monthly_costs_hiv_no i.under_lockdown log_monthly_timesclinic_hiv admitfacility arrangecare_hiv traveltime_hiv $updated_transport || facility_no:, family(gaussian) link(log) vce(robust)
	*M1 ADJ:
	meglm monthly_costs_hiv_no i.under_lockdown log_monthly_timesclinic_hiv admitfacility arrangecare_hiv traveltime_hiv $updated_transport age_p male secondary_ed employed expenditure_mill mstatus1 || facility_no:, family(gaussian) link(log) vce(robust)
	
	*M2
	meglm monthly_costs_hiv i.under_lockdown log_monthly_timesclinic_hiv admitfacility arrangecare_hiv traveltime_hiv $updated_transport losewages_hiv || facility_no:, family(gaussian) link(log) vce(robust)
	*M2 ADJ: 
	meglm monthly_costs_hiv i.under_lockdown log_monthly_timesclinic_hiv admitfacility arrangecare_hiv traveltime_hiv $updated_transport i.losewages_hiv age_p male secondary_ed employed expenditure_mill mstatus1 || facility_no:, family(gaussian) link(log) vce(robust)
	
	** Table 6
	**********
	*M3
	meglm m_totalcost_htn_no i.under_lockdown log_monthly_timesclinic_htn i.admit_htn arrangecare_htn traveltime_htn diffhtnfacility || facility_no:, family(gaussian) link(log) vce(robust)
	*M3 ADJ:
	meglm m_totalcost_htn_no i.under_lockdown log_monthly_timesclinic_htn i.admit_htn arrangecare_htn traveltime_htn diffhtnfacility age_p i.male secondary_ed employed expenditure_mill i.mstatus1 || facility_no:, family(gaussian) link(log) vce(robust)
	*M4 
	meglm m_totalcost_htn i.under_lockdown log_monthly_timesclinic_htn i.admit_htn arrangecare_htn traveltime_htn diffhtnfacility i.losewages_htn || facility_no:, family(gaussian) link(log) vce(robust)
		// does not converge
	*M4 ADJ: 
	meglm m_totalcost_htn i.under_lockdown log_monthly_timesclinic_htn i.admit_htn arrangecare_htn traveltime_htn diffhtnfacility i.losewages_htn age_p i.male secondary_ed employed expenditure_mill i.mstatus1 || facility_no:, family(gaussian) link(log) vce(robust)
	*/
	
		
******************************************************************************
** Testing imputation of missing expenditure data (Appendix Pg 838-41)
******************************************************************************
******************************************************************************

	*Imputed values
		sum spendpeople,d
		// MEAN = 158.2013
		// MEDIAN = 100.105
	
	*Adjusted spendpeople (per 100 USD) // Missing 12 observations with no data
		gen spendpeople_per=spendpeople/100
	
	*Mean  // imputing 12 ppl with mean values
	gen spendpeople_mean=spendpeople
		replace spendpeople_mean=158.2013
		replace spendpeople_mean=spendpeople_mean/100 // To make comparable to expenditure_mill 

	*Median // choice used to inpute 12 ppl with median values
			// tab expenditure_mill
		
	*OLS / GLM using only demographics
		regress spendpeople age_p male secondary_ed employed mstatus1 i.facility_no
			predict spendpeople_ols
			tab spendpeople_ols if spendpeople==.
			replace spendpeople_ols=spendpeople_ols/100
			
	*OLS / GLM using additional covariates // not included
		glm spendpeople i.under_lockdown log_monthly_timesclinic_hiv admitfacility arrangecare_hiv traveltime_hiv $updated_transport age_p male secondary_ed employed mstatus1 i.facility_no
			predict spendpeople_olsplus
			tab spendpeople_olsplus if spendpeople==.
			replace spendpeople_olsplus=spendpeople_olsplus/100


	* Now check each of the adjusted models to see how different each performs
	**************************************************************************
	
	foreach i of varlist expenditure_mill spendpeople_per spendpeople_mean spendpeople_ols {
	
	*Adjusted Model 1
	glm monthly_costs_hiv_no i.under_lockdown log_monthly_timesclinic_hiv admitfacility arrangecare_hiv traveltime_hiv $updated_transport age_p male secondary_ed employed `i' mstatus1 i.facility_no, link(log) vce(robust)
	est store ModelR1_`i'
	*Adjusted Model 2
	glm monthly_costs_hiv i.under_lockdown log_monthly_timesclinic_hiv admitfacility arrangecare_hiv traveltime_hiv $updated_transport i.losewages_hiv age_p male secondary_ed employed `i' mstatus1 i.facility_no, link(log) vce(robust)
	est store ModelR2_`i'
	*Adjusted Model 3
	glm m_totalcost_htn_no i.under_lockdown log_monthly_timesclinic_htn i.admit_htn arrangecare_htn traveltime_htn diffhtnfacility age_p i.male secondary_ed employed `i' i.mstatus1 i.facility_no, link(log) vce(robust)
	est store ModelR3_`i'
	*Adjusted Model 4
	glm m_totalcost_htn i.under_lockdown log_monthly_timesclinic_htn i.admit_htn arrangecare_htn traveltime_htn diffhtnfacility i.losewages_htn age_p i.male secondary_ed employed `i' i.mstatus1 i.facility_no, link(log) vce(robust)
	est store ModelR4_`i'
	}

	** Chosen median imputation
	outreg2 [ModelR1_expenditure_mill ModelR2_expenditure_mill ModelR3_expenditure_mill ModelR4_expenditure_mill] using "appendix/median_imputation.xls", side stats(coef se) label dec(2) excel addnote(Note: TBD) title("Median Imputation") replace	
	
	** No imputation
	outreg2 [ModelR1_spendpeople_per ModelR2_spendpeople_per ModelR3_spendpeople_per ModelR4_spendpeople_per] using "appendix/no_imputation.xls", side stats(coef se) label dec(2) excel addnote(Note: TBD) title("No Imputation") replace	

	** Mean Imputation
	outreg2 [ModelR1_spendpeople_mean ModelR2_spendpeople_mean ModelR3_spendpeople_mean ModelR4_spendpeople_mean] using "appendix/mean_imputation.xls", side stats(coef se) label dec(2) excel addnote(Note: TBD) title("Mean Imputation") replace	
	
	** OLS/GLM Imputation
	outreg2 [ModelR1_spendpeople_ols ModelR2_spendpeople_ols ModelR3_spendpeople_ols ModelR4_spendpeople_ols] using "appendix/ols_imputation.xls", side stats(coef se) label dec(2) excel addnote(Note: TBD) title("ols Imputation") replace	
	

	* stop Log File

************* END OF DO FILE *************



